package com.example.baseapp.activity

import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.GravityCompat
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.example.baseapp.R
import com.example.baseapp.adpter.ImageAdapter
import kotlinx.android.synthetic.main.activity_material_design.*
import kotlinx.android.synthetic.main.layout_bottom.*

class MaterialDesignActivity : AppCompatActivity() {
    private val images =
        mutableListOf(
            "李晨" to "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2401072376,669198433&fm=15&gp=0.jpg",
            "刘亦菲" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606467398120&di=b4f684adf6740f0bcdf433b8034420ee&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_mini%2Cc_zoom%2Cw_640%2Fimages%2F20170729%2F4fce3a33b34840dfaf0958f7423942ff.jpg",
            "韩雪" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606467245886&di=8750d31e7a4c12b132b77b1563b98161&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201802%2F20%2F20180220142148_ispoh.thumb.700_0.jpg",
            "毛晓彤" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606465970655&di=6c6d26902a07cb2ad79318e723e4f287&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fa%2F59ae34534ae90.jpg",
            "黄轩" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606468093884&di=17c4320a783823949f2cf956bb51e096&imgtype=0&src=http%3A%2F%2Fimages.rednet.cn%2Farticleimage%2F2017%2F06%2F26%2F135615695.jpg",
            "杨幂" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606466051947&di=001f1c28bc8a5b71b95eaa42cb11b0c6&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fc%2F57c7851e7dd00.jpg",
            "赵丽颖" to "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2277167488,290646067&fm=26&gp=0.jpg",
            "李泽" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606468410338&di=f6ad13323efcf1f7385f996da84450a6&imgtype=0&src=http%3A%2F%2Fd.ifengimg.com%2Fq100%2Fimg1.ugc.ifeng.com%2Fnewugc%2F20190116%2F18%2Fwemedia%2Fd26038558696b706dc78313ab49d40ed4074cf54_size174_w633_h950.jpg",
            "郑爽" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606467160936&di=f5f2c401a51e547e5e02dfe17d4a8e92&imgtype=0&src=http%3A%2F%2Fupload.taihainet.com%2F2016%2F0802%2F1470097328510.jpg",
            "陈赫" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606468170346&di=48109355225325d2b197941a8fe04061&imgtype=0&src=http%3A%2F%2Fa.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2Ff31fbe096b63f624db50805e8c44ebf81a4ca35a.jpg",
            "迪丽热巴" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606466362856&di=6af8686ff9ebeb1075e4a7002873a8e6&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201902%2F01%2F20190201121016_fbleb.jpg",
            "杨紫" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606466410049&di=5b084672408b531b380847919abaf450&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20190827%2F33e79f14c0dd45f6955e7e961e7a15b3.jpeg",
            "周冬雨" to "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=27586789,2648554908&fm=26&gp=0.jpg",
            "柳岩" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606467975862&di=4784f4fac2d3a2f68e4a99d0c6c5cf0b&imgtype=0&src=http%3A%2F%2Fimg3.doubanio.com%2Fview%2Fgroup_topic%2Fl%2Fpublic%2Fp88898022.jpg",
            "金晨" to "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606468255056&di=3f0526ca6133c837cbf30ffccb11cfa2&imgtype=0&src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_match%2F0%2F10752743444%2F0.jpg"
        )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_material_design)
        setSupportActionBar(toolsBar)
        // 显示标题和子标题
        //supportActionBar?.setDisplayShowTitleEnabled(false)
        toolsBar.setNavigationIcon(R.mipmap.menu)
        initImages()
    }

    private fun initImages() {
        rv_recycleView.layoutManager =
            StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)


        val adapter = ImageAdapter(data = images).apply {
            bindToRecyclerView(rv_recycleView)
        }
        swipe.setColorSchemeResources(
            R.color.purple_200,
            R.color.purple_500,
            R.color.teal_200,
            R.color.purple_700,

            )
        swipe.setOnRefreshListener {
            swipe.postDelayed({
                swipe.isRefreshing = false
                adapter.data.clear()

                adapter.notifyDataSetChanged()
            }, (0..5).random()*1000L)
        }
    }



    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.toolbar_menu, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            //导航键id
            android.R.id.home -> drawer.openDrawer(GravityCompat.START)
        }
        return super.onOptionsItemSelected(item)
    }

}